package it.apiconsulting.sharem.controller;

import it.apiconsulting.sharem.controller.bean.GuestBean;
import it.apiconsulting.sharem.dao.GuestDao;

import java.sql.Date;

import com.opensymphony.xwork2.ActionSupport;

public class RegisterGuestAction extends ActionSupport {

	private static final long serialVersionUID = 9149826260758390091L;
	private String username;
	private String idUser;
	
	private GuestDao linkGuestController;

	public RegisterGuestAction() {
		linkGuestController = new GuestDao();
	}

	public String execute() {
		return SUCCESS;
	}
	
	public String save() {
		
		Date dataCreazione = new Date(new java.util.Date().getTime());
		try {
			GuestBean guest = new GuestBean();
			guest.setIdUser(Long.parseLong(idUser));
			guest.setUsername(username);
			guest.setDatacreazione(dataCreazione);
			linkGuestController.add(guest);
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
		return SUCCESS;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getIdUser() {
		return idUser;
	}

	public void setIdUser(String idUser) {
		this.idUser = idUser;
	}

}